import request from '@/utils/request'

// 查询机构列表
export function listContract(query) {
  return request({
    // url: '/customer/contract/list',
    url: '/org/contract/list',
    method: 'get',
    params: query
  })
}

// 查询客户列表
export function getUserList(id) {
  return request({
    url: `/org/user/userList/${id}`,
    method: 'get'
  })
}

// 查询建筑列表
export function getBuildList(params) {
  return request({
    url: '/org/building/list',
    method: 'get',
    params
  })
}

// 查询系统列表
export function getDevList(params) {
  return request({
    url: '/org/device/systemList',
    method: 'get',
    params
  })
}

// 创建维保合同
export function createContract(data) {
  return request({
    url: '/org/contract',
    method: 'post',
    data
  })
}

// 获取维保合同详细
export function getCustomerDetail(id) {
  return request({
    url: `/customer/contract/${id}`,
    method: 'get'
  })
}

// 获取维保合同所有详细
export function getCustomerAllDetail(id) {
  return request({
    url: `/org/contract/allInfo/${id}`,
    method: 'get'
  })
}

// 获取附件
export function getUpAnnex(id, type) {
  return request({
    url: `/org/contract/annex/getAnnex/${id}/${type}`,
    method: 'get'
  })
}

// 保存附件
export function saveUpAnnex(data) {
  return request({
    url: `/org/contract/annex/saveAnnex`,
    method: 'post',
    data
  })
}

// 查询项目清单
export function getBillList(id) {
  return request({
    url: `/common/project/bill/list/${id}`,
    method: 'get'
  })
}

// 新增项目清单
export function addBillList(data) {
  return request({
    url: `/common/project/bill`,
    method: 'post',
    data
  })
}

// 编辑项目清单
export function putBillList(data) {
  return request({
    url: `/common/project/bill`,
    method: 'put',
    data
  })
}
// 删除项目清单
export function delBillList(id) {
  return request({
    url: `/common/project/bill/${id}`,
    method: 'delete'
  })
}



// 查询项目清单
export function getAdviseList(id) {
  return request({
    url: `/common/project/advise/list/${id}`,
    method: 'get'
  })
}

// 新增项目清单
export function addAdviseList(data) {
  return request({
    url: `/common/project/advise`,
    method: 'post',
    data
  })
}

// 删除项目清单
export function delAdviseList(id) {
  return request({
    url: `/common/project/advise/${id}`,
    method: 'delete'
  })
}


// 编辑项目清单
export function putAdviseList(data) {
  return request({
    url: `/common/project/advise`,
    method: 'put',
    data
  })
}

// 查询当前机构下的用户
export function getUserListType(type) {
  return request({
    url: `/org/user/userList/${type}`,
    method: 'get'
  })
}

// 根据类型获取协议列表
export function getTemplateList(type) {
  return request({
    url: `/org/template/list/${type}`,
    method: 'get'
  })
}

//获取公共模板列表
export function getTemplatePublicList(type) {
  return request({
    url: `/org/template/contractTemplate/${type}`,
    method: 'get'
  })
}

//预览维保合同
export function getContractPreview(contractId) {
  return request({
    url: `/org/contract/preview/${contractId}`,
    method: 'get'
  })
}

// 更新维保合同
export function putContract(data) {
  return request({
    url: `/org/contract`,
    method: 'put',
    data
  })
}

// 合同下载
export function dowRichText(data) {
  return request({
    url: `/richText/download`,
    method: 'post',
    data,
    responseType: 'blob',
  })
}


// 合同下载
export function resource(data) {
  return request({
    url: `/download/resource?resource=${data}`,
    method: 'get',
    responseType: 'blob',
  })
}
// 导出项目处理建议
export function adviseExport(data) {
  return request({
    url: `/common/project/advise/export?projectId=${data.id}`,
    method: 'post',
    data,
    responseType: 'blob',
  })
}
// 导出项目清单
export function billExport(data) {
  return request({
    url: `/common/project/bill/export?projectId=${data.id}`,
    method: 'post',
    data,
    responseType: 'blob',
  })
}
//查询付款计划
export function getPaymentPlan(id) {
  return request({
    url: `/org/contract/plan/getPaymentPlan/${id}`,
    method: 'get'
  })
}

//删除付款计划
export function deletePaymentPlan(id) {
  return request({
    url: `/org/contract/plan/deletePaymentPlan/${id}`,
    method: 'delete'
  })
}

//新增付款计划
export function addPaymentPlan(data) {
  return request({
    url: `/org/contract/plan/savePaymentPlan`,
    method: 'post',
    data
  })
}

//获取合同付款列表 
export function getPaymentList(contractId) {
  return request({
    url: `/org/payment/list/${contractId}`,
    method: 'get'
  })
}

// 根据付款计划ID查询合同付款记录
export function getPaymentRecords(paymentPlanId) {
  return request({
    url: `/org/payment/paymentRecords/${paymentPlanId}`,
    method: 'get'
  })
}

// 获取收付款信息
export function getReceiptPaymentInfo(id) {
  return request({
    url: `/org/payment/detail/${id}`,
    method: 'get'
  })
}

// 查询签订的合同
export function getSignedContract(id) {
  return request({
    url: `/org/contract/signedContract/${id}`,
    method: 'get'
  })
}

// 新增合同付款
export function addPayment(data) {
  return request({
    url: `/org/payment`,
    method: 'post',
    data
  })
}
// 修改合同付款
export function putPayment(data) {
  return request({
    url: `/org/payment`,
    method: 'put',
    data
  })
}

//根据附件id查询附件列表

export function getAnnexListById(id) {
  return request({
    url: `/org/contract/annex/listByIds/${id}`,
    method: 'get'
  })
}

//删除付款记录中的付款
export function deletePayment(id) {
  return request({
    url: `/org/payment/${id}`,
    method: 'delete'
  })
}
// 查询附件
export function getAnnexList(id) {
  return request({
    url: `/org/contract/annex/getAnnex/${id}`,
    method: 'get'
  })
}

//查看合同建筑信息
export function getContractBuildingInfo(id) {
  return request({
    url: `/org/contract/buildingInfo/${id}`,
    method: 'get'
  })
}


//生成维保方案
export function generateMaintenancePlan(id) {
  return request({
    url: `/org/contract/generateMaintenancePlan/${id}`,
    method: 'get'
  })
}

//终止项目
export function projectCancel(data) {
  return request({
    url: `/org/project/cancel`,
    method: 'post',
    data
  })
}


//机构获取公共的和本机构的模板

export function getTemplateListTpe() {
  return request({
    url: `/org/contract/getTemplateList`,
    method: 'get',
  })
}


//下载维保合同
export function downloadContractAll(id) {
  return request({
    url: `/org/contract/download/${id}`,
    method: 'get',
    responseType: 'blob',
  })
}


//删除附件
export function deleteAnnex(id) {
  return request({
    url: `/org/contract/annex/deleteAnnex/${id}`,
    method: 'delete'
  })
}

// 合同签章发送验证码
export function sendMsgCode(contractId) {
  return request({
    url: `/org/contract/sign/sendMsgCode/${contractId}`,
    method: 'get'
  })
}

// 验证验证码
export function validateCode(data) {
  return request({
    url: `/org/contract/sign/validateCode`,
    method: 'post',
    data
  })
}



